package com.itheima.service;


import com.itheima.config.HystrixConfig;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate;

//@FeignClient(value = "hystrix-provider",configuration = HystrixConfig.class,fallback = LocalItemService.class)
//public interface LocalItemService{
//    @RequestMapping(value = "/hi", method = RequestMethod.GET)
//    public String hi(@RequestParam(value = "id")String id);
//}
@Service
public class LocalItemService {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String hi(String id) {
        return restTemplate.getForObject("http://hystrix-provider/hi?id=" + id, String.class);
    }

    public String hiError(String id) {
        return String.format("Hi，your message is : %s but  request bad.【32+A2+庄远虹】", id);
    }
}
